<?  layout("../layout/default.html") { ?>
<script type="text/javascript" src="${root}/Static/js/jquery.tmpl.js"></script>
<form method="post" action="123123213/deleteAll">
<div class="admin-panel">		
    <div class="panel">
    	<div class="panel-head">
            <h3 class="float-left"><b>部门列表</b> <a href="${root}/Dept/create" class="button  button-little bg-blue  icon-plus"> 添加一级部门</a></h3>
            <div class="toolbar">                    
            </div>
            <div class="clearfix"></div>
        </div>        
		<div class="panel-body" deptid="0">
		</div>
        <div class="panel-foot text-center">
        <?  includeFileTemplate("/common/paginate.html",{uri : '', page : page}){}?>            
        </div>
    </div>
</div>
</form>
<script id="deptTpl" type="text/x-jquery-tmpl">
<ul class="dept-item" deptid="\${id}" loadflg="0">
    <li class="dept-item-info"  {%if haschild==true%}child="1"{%/if%}>
		<a class="{%if haschild==true%}icon-angle-down{%/if%}" onclick="toggle(\${id})" href="javascript:;"></a>
		<a href="${root}${ControllerKey}/update/\${id}">\${cname}</a>&nbsp;&nbsp;
		<a class="icon-plus text-blue hidden" href="${root}${ControllerKey}/create/\${id}"> </a>
		<a class="icon-trash-o text-red hidden" onclick="return checkDel(\${id})" href="${root}${ControllerKey}/delete/\${id}"> </a>
    </li>
</ul>
</script>
<script type="text/javascript">
var checkDel = function(id){
	if($(".dept-item[deptid='"+id+"'] ul").size()>0){
		alert("无法执行：依然含有子项。");
		return false;
	}
	return confirm("确定删除？");
}
var toggle = function(id){
	$(".dept-item[deptid='"+id+"'] ul").toggle();    	
	$(".dept-item[deptid='"+id+"'] li:first[child='1']").children("a:first").toggleClass("icon-caret-right");
	$(".dept-item[deptid='"+id+"'] li:first[child='1']").children("a:first").toggleClass("icon-angle-down");
}
var showChildren = function(data,pid){
	var children = $.grep(data,function(n,i){return n.pid==pid;})
	$.each(children, function(i, row){
		$("#deptTpl").tmpl(row).appendTo("[deptid='"+pid+"']")
		if(row.haschild==true)
			showChildren(data,row.id);
	});
}
$.get("${root}${ControllerKey}/getlist",function(json){
	showChildren(json.data,0);
},"JSON");
$(".panel-body").delegate(".dept-item-info", "mouseover", function(){
    $("a:gt(1)",this).removeClass('hidden')
});
$(".panel-body").delegate(".dept-item-info", "mouseout", function(){
    $("a:gt(1)",this).addClass('hidden')
});
</script>
<?  } ?>
